<template>
  <div>
    <div style="display:flex;flex-wrap:wrap;cursor:pointer">
      <el-card
        shadow="hover"
        v-for="(item, index) in tjdcl"
        :key="index"
        style="margin-bottom:20px;width:30%;margin-left:2%"
      >
        <div @click="checkspdata(item)">
          <p style="line-height:30px">
            <span style="color:#26a2ff;font-size:17px">{{item.hash.createusername}}</span>
            <span style="color:#686868;font-size:14px;margin-left:10px">{{item.hash.intime}} 提交了</span>
          </p>
          <p
            style="line-height:15px;font-size:13px;margin-bottom:5px;color:rgb(144, 147, 153)"
          >{{item.hash.bumen}}</p>
          <p style="line-height:40px;font-size:18px">{{item.hash.atypename}}</p>
          <p style="line-height:20px;font-size:14px;color:#909399">{{item.hash.content}}</p>
          <p style="line-height:40px;display:flex">
            <b v-if="item.hash.status=='1'">审批中</b>
            <b v-if="item.hash.status=='-1'" style="color:red">被驳回</b>
            <b v-if="item.hash.status=='0'" style="color:#666666">申请人撤回</b>
            <b v-if="item.hash.status=='2'">通过</b>
            <i
              class="el-icon-user"
              style="margin-top:10px; margin-left:10px;color:rgb(29, 206, 87);"
            ></i>
            <b
              style="margin-right:10px;color:rgb(29, 206, 87);font-size:14px"
            >{{item.hash.caozuoren}}</b>
            <span style="color:#686868">{{item.hash.maxrecordtime}}</span>
          </p>
          <p style="text-align:right;">
            <span v-if="activeName=='first2'||activeName=='first3'">
              <el-button
                size="mini"
                v-if="item.hash.status=='1'"
                type="danger"
                @click.stop="withdraw(item)"
              >撤 回</el-button>
              <el-button
                size="mini"
                v-if="item.hash.status=='-1'||item.hash.status=='0'"
                type="success"
                @click.stop="resubmit(item)"
              >重新提交</el-button>
            </span>
          </p>
        </div>
      </el-card>
    </div>
    <el-row>
      <el-pagination
        @current-change="handleCurrentChange"
        :currentPage.sync="pagobj.currentPage3"
        :pageSize="pagobj.pagesize"
        layout="total, prev, pager, next"
        :total="pagobj.total"
        style="margin:20px 0;text-align:center"
      ></el-pagination>
    </el-row>
    <checksp
      :nowapprovalid="nowapprovalid"
      v-if="ischecksp"
      :isnew="false"
      :atypeid="atypeid"
      :checkitem="checkitem"
      :fun="fun2"
    ></checksp>

    <el-dialog :title="'重新提交'+title" :visible.sync="showresub">
      <leaveform
        v-if="isleaveform"
        :timename="'请假时间'"
        :checkdetail="checkdetail"
        :status="2"
        :fun="fun2"
      ></leaveform>
      <repairform v-if="isrepairform" :status="2" :checkdetail="checkdetail" :fun="fun2"></repairform>
      <gooutform v-if="isgooutform" :status="2" :checkdetail="checkdetail" :fun="fun2"></gooutform>
      <moneyform
        v-if="ismoneyform"
        :status="2"
        :checkdetail="checkdetail"
        :fun="fun2"
        @closedia="closedia"
      ></moneyform>
      <carform v-if="iscarform" :status="2" :checkdetail="checkdetail" :fun="fun2"></carform>
      <reimform v-if="isreimform" :status="2" :checkdetail="checkdetail" :fun="fun2"></reimform>
      <contractform v-if="iscontractform" :status="2" :checkdetail="checkdetail" :fun="fun2"
        @closedia="closedia"
      ></contractform>
    </el-dialog>
  </div>
</template>

<script>
import leaveform from '~/components/sptype/leave.vue';
import checksp from '~/components/apply/checksp';
import repairform from '~/components/sptype/repair.vue';
import gooutform from '~/components/sptype/goout.vue';
import moneyform from '~/components/sptype/money.vue';
import carform from '~/components/sptype/car.vue';
import reimform from '~/components/sptype/reim.vue';
import contractform from '~/components/sptype/contract.vue';

export default {
  props: {
    tjdcl: {
      type: Array,
      required: true,
    },
    activeName: String,
    fun: Function,
    pagobj: Object,
  },
  components: {
    checksp,
    leaveform,
    repairform,
    gooutform,
    moneyform,
    carform,
    reimform,
    contractform,
  },
  data() {
    return {
      ts: this.newStore(),

      title: '',
      atypeid: '',
      showresub: false,
      isleaveform: false,
      isrepairform: false,
      isgooutform: false,
      ismoneyform: false,
      iscarform: false,
      isreimform: false,
      iscontractform: false,
      nowapprovalid: '',
      ischecksp: false,
      checkitem: {
        hash: {
          atype: '',
        },
      },
      checkdetail: {},
    };
  },
  methods: {
    handleCurrentChange() {
      this.fun();
    },
    // 关闭弹窗
    closedia(val) {
      this.showresub = val;
    },
    // 公共组件刷新
    reload(partsname) {
      // console.log(partsname);
      this[partsname] = false;
      this.$nextTick(() => {
        this[partsname] = true;
      });
    },
    checkspdata(item) {
      console.log(item);
      this.checkitem = item;
      this.nowapprovalid = item.hash.id;
      localStorage.setItem('id', item.hash.id);
      this.reload('ischecksp');
    },
    // 审批重新提交
    resubmit(item) {
      if (item.hash.atype == '0103') {
        this.atypeid = '0103';
        this.gettypedetail(
          'BD6A960AF46EE09F9C5B42D1658B3CCCA5A715B191607392',
          item,
          'isleaveform',
        );
        this.isrepairform = false,
        this.isgooutform = false,
        this.ismoneyform = false,
        this.iscarform = false,
        this.isreimform = false,
        this.iscontractform = false;
      } else if (item.hash.atype == '0106') {
        this.atypeid = '0106';
        this.gettypedetail(
          '9DEA590540016AF56AA8E4B54801438BB3F2193D08E31332D5E5601D2F82C2E672B5B64895E2F11C',
          item,
          'isrepairform',
        );
        (this.isleaveform = false),
        (this.isgooutform = false),
        (this.ismoneyform = false),
        (this.iscarform = false),
        (this.isreimform = false),
        (this.iscontractform = false);
      } else if (item.hash.atype == '0105') {
        this.atypeid = '0105';
        this.gettypedetail(
          '06BBA4638D6221E7C94D5152B4CB8D877A1F05FDC4A221F3FC134F422ABAA2D3DADB28EFE659DCF9',
          item,
          'isgooutform',
        );
        (this.isleaveform = false),
        (this.isrepairform = false),
        (this.ismoneyform = false),
        (this.iscarform = false),
        (this.isreimform = false),
        (this.iscontractform = false);
      } else if (item.hash.atype == '0102') {
        this.atypeid = '0102';
        this.gettypedetail(
          '40236578C287949E983CF935CC2173FE347A69929FDF7F2FE251F12C1C7E6A4B0FE3786F0F962D11',
          item,
          'ismoneyform',
        );
        (this.isleaveform = false),
        (this.isrepairform = false),
        (this.isgooutform = false),
        (this.iscarform = false),
        (this.isreimform = false),
        (this.iscontractform = false);
      } else if (item.hash.atype == '0104') {
        this.atypeid = '0104';
        this.gettypedetail(
          '27C5BBCC57742906E0FD67DAD8D2622896D1E3093AF33DA156AD69D48355AA75947C61655EDF54FA',
          item,
          'iscarform',
        );
        (this.isleaveform = false),
        (this.isrepairform = false),
        (this.isgooutform = false),
        (this.ismoneyform = false),
        (this.isreimform = false),
        (this.iscontractform = false);
      } else if (item.hash.atype == '0101') {
        this.atypeid = '0101';
        this.gettypedetail(
          '0398B14C0EC6F01867D31307B7D9BCF99F9190F74AA3A4C7C5EECFEA4B2A82E4BFF0B9210751F692',
          item,
          'isreimform',
        );
        (this.isleaveform = false),
        (this.isrepairform = false),
        (this.isgooutform = false),
        (this.ismoneyform = false),
        (this.iscarform = false),
        (this.iscontractform = false);
      } else if (item.hash.atype == '0107') {
        this.atypeid = '0107';
        this.gettypedetail(
          '09D3B9E20F101E11CD5ED14F3DA05EF7E5F8A7980C727D360C5596A61637D2F6FC5D937ABF463C840FE3786F0F962D11',
          item,
          'iscontractform',
        );
        (this.isleaveform = false),
        (this.isrepairform = false),
        (this.isgooutform = false),
        (this.ismoneyform = false),
        (this.isreimform = false),
        (this.iscarform = false);
      }
    },
    gettypedetail(handle, item, atypename) {
      const req = {
        handle,
        aid: item.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.checkdetail = ts.d.data;
        this.title = item.hash.atypename;
        this.reload(atypename);
        this.showresub = true;
      });
    },
    fun2() {
      this.showresub = false;
      this.fun();
    },
    // 提交撤回
    withdraw(item) {
      console.log(item);

      const res = {
        handle:
          '9000B8B8D347526960C5BAB1FB6894EF8840DAE4ED8972730B580809D549F3A2883DD87A60EFB7C7',
        approvalid: item.hash.id,
      };
      this.$confirm('确定提交撤回审批, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.spost(this.ts, '/mainservlet', res).then((ts) => {
            if (ts.d.data.operation1[0].hash.msg == 'success') {
              this.$message({
                type: 'success',
                message: '提交成功!',
              });
              this.fun2();
            } else {
              this.$message({
                type: 'error',
                message: ts.d.data.operation1[0].hash.msg,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
  },
};
</script>

<style>
</style>
